package cn.xz.xy.activity

import cn.xz.xy.MainActivity
import cn.xz.xy.R
import cn.xz.xy.base.BaseActivity
import cn.xz.xy.bean.CommonLib
import cn.xz.xy.bean.DateLogin
import cn.xz.xy.databinding.ActivityLoginBinding
import cn.xz.xy.dialog.LoseAppDialog
import cn.xz.xy.util.ARouter
import cn.xz.xy.util.SessionUtils
import java.text.DateFormat
import java.text.SimpleDateFormat

class LoginActivity : BaseActivity<ActivityLoginBinding>(R.layout.activity_login)  {

    //当前Logo点击次数
    private var logoNum = 0
    //上次点击logo时间
    private var lastLogoTime = 0L

    override fun initEvent() {
        //Logo
        mDataBind.ivLogo.setOnClickListener {
            //连点五次进入数据下载界面
            if (System.currentTimeMillis() - lastLogoTime > 2000) {
                logoNum = 0
                lastLogoTime = System.currentTimeMillis()
            } else {
                logoNum++
                if (logoNum >= 5) {
                    ARouter.to(LoadingActivity::class.java)
                }
            }
        }
        //文化馆
        mDataBind.llcCwh.setOnClickListener {
            ARouter.to(MainActivity::class.java)
        }
        //上合会客ting
        mDataBind.llcHkt.setOnClickListener {
             ARouter.to(MainHKActivity::class.java)
        }

    }


    override fun onResume() {
        super.onResume()
        //判断应用是否过期，如果过期弹窗禁止使用
        val dateLogin = SessionUtils.getObject<DateLogin>(CommonLib.Date_Login, DateLogin::class.java)
        if (dateLogin != null){
            //正式版不处理
            if (dateLogin.states != 1){
                val format: DateFormat = SimpleDateFormat("yyyy-MM-dd")
                val fwqTime = format.parse(dateLogin.date).time
                if (fwqTime < System.currentTimeMillis()){
                    LoseAppDialog.newInstance(true,object : LoseAppDialog.OnClickListener{
                        override fun onF() {
                            finish()
                        }
                    }).show(this.supportFragmentManager,"LoseAppDialog")
                }
            }
        }else{
            LoseAppDialog.newInstance(false,object : LoseAppDialog.OnClickListener{
                override fun onF() {

                }
            }).show(this.supportFragmentManager,"LoseAppDialog2222")
        }
    }

}